package ace.cmp.spring.data.jdbc.querydsl.core.util;

import ace.cmp.spring.data.jdbc.querydsl.core.QuerydslRelationHelper;

/**
 * @author caspar
 * @date 2024/2/22 10:54
 */
public class DeleteFlagUtils {

  public static void setQuerydslRelationHelper(QuerydslRelationHelper querydslRelationHelper) {
    DeleteFlagUtils.querydslRelationHelper = querydslRelationHelper;
  }

  private static QuerydslRelationHelper querydslRelationHelper;

  public static Boolean isDelete(Object object) {
    if (object == null) {
      return Boolean.TRUE;
    }
    Object objectLogicDeleteFlagFieldValue =
        querydslRelationHelper.getLogicDeleteFieldValue(object);
    if (objectLogicDeleteFlagFieldValue == null) {
      return Boolean.FALSE;
    }
    Object logicNotDeleteFlagValue =
        querydslRelationHelper.getLogicNotDeleteFlagValue(object.getClass());
    if (logicNotDeleteFlagValue == null) {
      return Boolean.FALSE;
    }
    return !logicNotDeleteFlagValue.equals(objectLogicDeleteFlagFieldValue);
  }

  public static Boolean isNotDelete(Object object) {
    return !isDelete(object);
  }
}
